<template>
  <div>
    <!--    添加院系-->
    <div id="form">
      <el-form label-width="280px" :model="department">
        <el-form-item label="院系名称">
          <el-input v-model="department.depname" placeholder="请输入院系名称" style="width:100% "></el-input>
        </el-form-item>
        <el-form-item label="成立时间" style="margin-top: 50px">
          <el-col>
            <el-date-picker v-model="department.date" value-format="yyyy-MM-dd" style="width: 100%;" type="date"
                            placeholder="选择日期"></el-date-picker>
          </el-col>
        </el-form-item>
        <el-form-item style="margin-top: 50px;">
          <el-button style="margin-right: 30px" type="primary" @click="onSubmit">立即添加</el-button>
          <el-button type="info" @click="onClean">重新输入</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import departmentApi from '@/api/department'
import qs from "qs";
export default {
  name: "add",
  data() {
    return {
      department: {
        depname: "",
        date: ""
      },
    }
  },
  methods: {
    //点击添加
    onSubmit() {
      departmentApi.addDepartment(qs.stringify(this.department)).then(resp => {
        if (resp.code === 6666) {
          this.$message.success("添加成功！");
          this.onClean();
          this.$router.push('/department/list')
        } else {
          this.$message.info(resp.msg)
        }
      }).catch(() => {
        this.$message.error("添加失败！")
      })
    },
    //清楚已输入的数据
    onClean() {
      this.department = {}
    }
  }
}
</script>

<style scoped>
#form {
  width: 680px;
  height: 400px;
  margin-top: 150px;
}
</style>
